package io.renren.service.repair.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;

import io.renren.dao.repair.RepairEvaluationDao;

import io.renren.dto.repair.RepairEvaluationDTO;
import io.renren.entity.repair.RepairEvaluationEntity;
import io.renren.service.repair.RepairEvaluationService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 报修评价表
 *
 * @author dio 167762802@QQ.com
 * @since 1.0.0 2025-04-12
 */
@Service
public class RepairEvaluationServiceImpl extends CrudServiceImpl<RepairEvaluationDao, RepairEvaluationEntity, RepairEvaluationDTO> implements RepairEvaluationService {

    @Override
    public QueryWrapper<RepairEvaluationEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<RepairEvaluationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }

    /**
     * 根据报修ID获取评价
     * @param repairId 报修ID
     * @return 评价信息
     */
    @Override
    public RepairEvaluationEntity getByRepairId(Long repairId) {
        QueryWrapper<RepairEvaluationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("repair_id", repairId);
        return baseDao.selectOne(wrapper);
    }
    
    /**
     * 判断报修是否已评价
     * @param repairId 报修ID
     * @return 是否已评价
     */
    @Override
    public boolean isEvaluated(Long repairId) {
        QueryWrapper<RepairEvaluationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("repair_id", repairId);
        Long count = baseDao.selectCount(wrapper);
        return count != null && count > 0;
    }
}